package ikelib;

public class winindex {
	public winindex(){
		dataoffset = ch=enc=rate=0;
		time = new wintime();
	}
	public winindex(winindex w){
		file = w.file;
		dataoffset = w.dataoffset;
		ch = w.ch;
		enc = w.enc;
		rate = w.rate;
		time = new wintime(w.time);
	}
	public String fmt(){
		String s = String.format("%s offset=%12d %s ch=%x encode=%d rate=%d",getTruncateFilename(file,30,20),dataoffset,time.fmt(),ch,enc,rate);
		return s;
	}
	private String getTruncateFilename(String longname,int maxlength,int minfilenamelength){
		String ret = new String();
		if(longname.length() > maxlength){
			ret = longname.substring(0, maxlength-3-minfilenamelength);
			ret += "...";
			ret += longname.substring(longname.length()-minfilenamelength,longname.length());
		}
		else{
			ret = longname;
		}
		return ret;
	}
	public String file;
	public int    dataoffset;
	public int ch;
	public int	    enc;
	public int		rate;
	public wintime time;
	
	public static String getChannelName(int channel){
		String ret = new String();
		for(int i=0;i<4;i++){
			ret = String.format("%X", channel & 0xf) + ret;
			channel >>= 4;
		}
		return ret;
	}
}
